CLASS lhc_ypsm0010_i_menu DEFINITION INHERITING FROM cl_abap_behavior_handler.

  PRIVATE SECTION.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR ypsm0010_i_menu RESULT result.
    METHODS deletemenuwithcheck FOR MODIFY
      IMPORTING keys FOR ACTION ypsm0010_i_menu~deletemenuwithcheck RESULT result.
    METHODS get_instance_features FOR INSTANCE FEATURES
      IMPORTING keys REQUEST requested_features FOR ypsm0010_i_menu RESULT result.

ENDCLASS.

CLASS lhc_ypsm0010_i_menu IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD deletemenuwithcheck.
    reported-ypsm0010_i_menu = VALUE #( ).
  ENDMETHOD.

  METHOD get_instance_features.
  ENDMETHOD.

ENDCLASS.

CLASS lhc_ypsm0010_i_form DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR ypsm0010_i_form RESULT result.
    METHODS deletewithcheck FOR MODIFY
      IMPORTING keys FOR ACTION ypsm0010_i_form~deletewithcheck RESULT result.
*    METHODS deletewithcheck FOR MODIFY
*      IMPORTING keys FOR ACTION ypsm0010_i_form~deletewithcheck RESULT result.

**********************************************************************

ENDCLASS.

CLASS lhc_ypsm0010_i_form IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD deletewithcheck.
    DATA lt_formid_menu TYPE STANDARD TABLE OF ypsm0010_i_form-formid.
    DATA lt_formid_text TYPE STANDARD TABLE OF ypsm0010_i_form-formid.

    LOOP AT keys INTO DATA(ls_key).
      SELECT *
      FROM ypsm0010_dt_menu
      WHERE form_id = @ls_key-formid
      INTO TABLE @DATA(lt_menu).

      IF lt_menu IS NOT INITIAL.
        APPEND ls_key-formid TO lt_formid_menu.
      ENDIF.

      SELECT *
      FROM ypsm0010_dt_text
      WHERE formid = @ls_key-formid
      INTO TABLE @DATA(lt_text).

      IF lt_text IS NOT INITIAL.
        APPEND ls_key-formid TO lt_formid_text.
      ENDIF.
    ENDLOOP.

    MODIFY ENTITIES OF ypsm0010_i_form IN LOCAL MODE
        ENTITY ypsm0010_i_form
            DELETE FROM CORRESPONDING #( keys )
        FAILED failed
        REPORTED reported.

    if lt_formid_text is not INITIAL.
      MODIFY ENTITIES OF ypsm0010_i_form IN LOCAL MODE
        ENTITY ypsm0010_i_text
            DELETE FROM VALUE #( for lvformid in lt_formid_text ( FormId = lvformid ) ).
    ENDIF.

    IF lt_formid_menu IS NOT INITIAL.
      MODIFY ENTITIES OF ypsm0010_i_form IN LOCAL MODE
        ENTITY ypsm0010_i_menu
            DELETE FROM VALUE #( for lv_formid in lt_formid_menu ( FormId = lv_formid ) ).
      reported-ypsm0010_i_form = VALUE #(
          FOR ls_formid IN lt_formid_menu (
              %msg = new_message(
                  id = 'YPSM0010_AMC_01'
                  number = 001
                  v1 = ls_formid
                  severity = if_abap_behv_message=>severity-warning )
              %delete = if_abap_behv=>mk-on
          )
      ).
    ENDIF.

    result = VALUE #( ).
  ENDMETHOD.

ENDCLASS.
